package com.exercise.ThreadAttribute;

/**
 * 线程存活状态
 */
public class ThreadAliveExample {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        //false
        System.out.println("Before start: " + thread.isAlive());
        thread.start();
        System.out.println("After start: "+thread.isAlive());
        //让主线程等待子线程完成
        thread.join();
        System.out.println("After completion: " + thread.isAlive());
    }
}
